home *** CD-ROM | disk | FTP | other *** search
/ The Complete Utilities To…ka 501 Killer Utilities! / 501 Killer Utilities! (Macworld July 1995).cdr / Programming / OutOfPhase1.1 Source / OutOfPhase Folder / ASTPrintString.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-27  |  4.0 KB  |  117 lines  |  [TEXT/KAHL]

  1. /* ASTPrintString.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "ASTPrintString.h"
  31. #include "TrashTracker.h"
  32. #include "Memory.h"
  33. #include "ASTExpression.h"
  34.  
  35.  
  36. struct ASTPrintStringRec
  37.     {
  38.         char*                                MessageString;
  39.         long                                LineNumber;
  40.     };
  41.  
  42.  
  43. /* create a new AST string print */
  44. ASTPrintStringRec*    NewPrintString(char* String, struct TrashTrackRec* TrashTracker,
  45.                                             long LineNumber)
  46.     {
  47.         ASTPrintStringRec*    PrintString;
  48.  
  49.         PrintString = (ASTPrintStringRec*)AllocTrackedBlock(sizeof(ASTPrintStringRec),
  50.             TrashTracker);
  51.         if (PrintString == NIL)
  52.             {
  53.                 return NIL;
  54.             }
  55.         SetTag(PrintString,"ASTPrintStringRec");
  56.  
  57.         PrintString->MessageString = String;
  58.         PrintString->LineNumber = LineNumber;
  59.  
  60.         return PrintString;
  61.     }
  62.  
  63.  
  64. /* type check the string print node.  this returns eCompileNoError if */
  65. /* everything is ok, and the appropriate type in *ResultingDataType. */
  66. CompileErrors                TypeCheckPrintString(DataTypes* ResultingDataType,
  67.                                             ASTPrintStringRec* PrintString, long* ErrorLineNumber,
  68.                                             struct TrashTrackRec* TrashTracker)
  69.     {
  70.         CheckPtrExistence(PrintString);
  71.         CheckPtrExistence(TrashTracker);
  72.  
  73.         *ResultingDataType = eBoolean;
  74.         return eCompileNoError;
  75.     }
  76.  
  77.  
  78. /* generate code for a string print.  returns True if successful, or False if it fails. */
  79. MyBoolean                        CodeGenPrintString(struct PcodeRec* FuncCode,
  80.                                             long* StackDepthParam, ASTPrintStringRec* PrintString)
  81.     {
  82.         long                            StackDepth;
  83.  
  84.         CheckPtrExistence(FuncCode);
  85.         CheckPtrExistence(PrintString);
  86.         StackDepth = *StackDepthParam;
  87.  
  88.         /* do the thing */
  89.         if (!AddPcodeInstruction(FuncCode,epPrintString,NIL))
  90.             {
  91.                 return False;
  92.             }
  93.         if (!AddPcodeOperandString(FuncCode,PrintString->MessageString,
  94.             PtrSize(PrintString->MessageString)))
  95.             {
  96.                 return False;
  97.             }
  98.  
  99.         /* return value */
  100.         if (!AddPcodeInstruction(FuncCode,epLoadImmediateInteger,NIL))
  101.             {
  102.                 return False;
  103.             }
  104.         if (!AddPcodeOperandInteger(FuncCode,True))
  105.             {
  106.                 return False;
  107.             }
  108.  
  109.         /* error instruction leaves a return code, after consuming its operand. */
  110.         StackDepth += 1;
  111.         ERROR(StackDepth != *StackDepthParam + 1,PRERR(ForceAbort,
  112.             "CodeGenPrintString:  stack depth error after pushing return value"));
  113.  
  114.         *StackDepthParam = StackDepth;
  115.         return True;
  116.     }
  117.